<template>
  <nut-searchbar v-model="searchTxt" placeholder="搜索商品" @search="search" @clear="clear"  />
  <goodItem ref="goodItemRef" :buId="buId" :buName="buName" />
</template>
<script setup>
// 零售
import bus from "@/utils/bus.js";
import goodItem from '../stock/comm/kc_good.vue'
import {onBeforeMount, onMounted, onUnmounted, ref} from "vue";
import {useRoute} from "vue-router";
const searchTxt = ref('')
const buId = ref('')
const buName = ref('')
const goodItemRef = ref(null)
const route = useRoute()
onBeforeMount(() => {
  buId.value = route.query.buId
  buName.value = route.query.buName
})
onMounted(() => {
  bus.$on('scan-bar', scanRet)
})
onUnmounted(() => {
  bus.$off('scan-bar', scanRet)
})
const clear = () => {
  search('')
}
const search = () => {
  goodItemRef.value.search(searchTxt.value)
}
const scan = () => {
  if(typeof uni !== 'undefined') {
    // eslint-disable-next-line no-undef
    uni.postMessage({
      data: {
        type: 'scan'
      }
    })
  }
}
const scanRet = (code) => {
  if(code) {
    goodItemRef.value.scanRet(code)
  }
}

</script>

<style scoped lang="scss">


</style>